import { Component, OnInit, Input, EventEmitter, Output, Host, Inject, forwardRef, ViewChild, ElementRef, AfterViewInit } from '@angular/core';

import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';
import { Service } from '../../../server/server';
import { HintsService } from '../../../public/serve/hints/hints.service';
declare var $: any;

@Component({
  selector: 'app-effect-delete',
  templateUrl: './effect-delete.component.html',
})
export class EffectDeleteComponent implements OnInit {

  constructor(private removeTableService: RemoveTableService, private service: Service,private hintsService:HintsService) { }

  ngOnInit() {
  }

  @Output() deleteOutput = new EventEmitter<string>();

  // 确认删
  confirmDel() {

    let url = this.service.baseUrl+'user/functions/deleteInfo';

    this.removeTableService
      .confirmRemove('functionId', url)
      .then((res: any) => {
        if(res.result_code) {
          this.hintsService.messages(res.message,res.result_code);
          this.deleteOutput.emit(res.result_code)
        }
      }).catch((err: any) => {
        console.error('请检查您的网络！');
        return false;
      });
    $('#delete').modal('hide');
  }

  /**
  * 操作提示
  * @param whichHints
  */
  operationHints(hintsTxt: string, whichHints: string) {
    switch (whichHints) {
      case 'success':
        this.service.prompt = { prompt: true, success: true, fail: false, promptStatement: hintsTxt };
        this.service.promptclose;
        break;
      case 'fail':
        this.service.prompt = { prompt: true, success: false, fail: true, promptStatement: hintsTxt };
        this.service.promptclose = [];
        break;
    }
  }

}
